import {createSlice} from "@reduxjs/toolkit"
import axios from "axios";
export const conterSlice = createSlice({
    name:"counter",
    initialState : {
        count :1,
        title:"redux tookit",
        arr:[]
    },
    reducers:{   // 创建完reducers回自动生成action
        fn (state,{payload}) {
            console.log(payload);
            state.count = state.count + payload.step
        },
        del (state,action) {
            state.count = state.count  - 1
        },
        setArr (state,{payload}) {
            console.log(payload);
            state.arr = payload
        }
    }
})
export const {fn,del,setArr} = conterSlice.actions // 抛出这些action
// tookit 内置了thunk
export const getlist = (data)=>{  return (dispatch)=>{
    axios.get("/api/list").then(res=>{
        console.log(res.data);
        dispatch(setArr(data))
    })
}
}



export default conterSlice.reducer